package com.fjb.controller.user;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonPagesResult;
import com.fjb.common.entity.JsonResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.controller.base.BaseController;
import com.fjb.dto.LoginUserInfo;
import com.fjb.pojo.user.vo.UserCollectVo;
import com.fjb.service.user.SysUserCollectService;

/**
 * <p>
 * 用户收藏 前端控制器
 * </p>
 *
 * @author hemiao
 * @since 2019-12-22
 */
@Controller
@RequestMapping("/userCollect")
public class SysUserCollectController extends BaseController{
	
	@Autowired
	private SysUserCollectService sysUserCollectService;
	
	/**
	 * @Description:添加产品收藏
	 * @param request
	 * @param productId
	 * @return
	 * JsonResult<Boolean>
	 * @exception:
	 * @author: hemiao
	 * @time:2020年2月19日 下午9:22:59
	 */
	@RequestMapping(value="/addProduct")
	@ResponseBody
	public JsonResult<Boolean> addProduct(HttpServletRequest request,Integer productId){
		HttpCode httpCode = HttpCode.PARAM_VERIFICATION;
		if(productId==null) {
			return new JsonResult<Boolean>(null, httpCode);
		}
		LoginUserInfo userInfo = getBaseWxTokenId(request);
		return sysUserCollectService.addProduct(userInfo, productId);
	}
	
	/**
	 * @Description:取消产品收藏
	 * @param request
	 * @param productId
	 * @return
	 * JsonResult<Boolean>
	 * @exception:
	 * @author: hemiao
	 * @time:2020年2月19日 下午9:22:51
	 */
	@RequestMapping(value="/deleteProduct")
	@ResponseBody
	public JsonResult<Boolean> deleteProduct(HttpServletRequest request,Integer productId){
		HttpCode httpCode = HttpCode.PARAM_VERIFICATION;
		if(productId==null) {
			return new JsonResult<Boolean>(null, httpCode);
		}
		LoginUserInfo userInfo = getBaseWxTokenId(request);
		Integer userId = userInfo.getUserId();
		return  sysUserCollectService.deleteProduct(productId, userId);
	}
	
	/**
	 * @Description:查询收藏列表
	 * @param request
	 * @param pageQuery
	 * @return
	 * JsonPagesResult<List<UserCollectVo>>
	 * @exception:
	 * @author: hemiao
	 * @time:2020年2月25日 下午11:15:57
	 */
	@RequestMapping(value="/selectPageList")
	@ResponseBody
	public JsonPagesResult<List<UserCollectVo>> selectPageList(HttpServletRequest request,PageQuery pageQuery){
		LoginUserInfo userInfo = getBaseWxTokenId(request);
		Integer userId = userInfo.getUserId();
		return sysUserCollectService.selectPageList(pageQuery, userId);
	}
}
